<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html{
            width: 3000px;
            height: 5000px;
        }
        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

<script>
    // onresize 窗口大小改变时触发
    // resizeHandler(); // 页面加载时触发
    // window.onresize = function(){}; //  绑定事件时赋值的是函数
    // window.onresize = resizeHandler; //  窗口大小改变时触发


    // onscroll 滚动条滚动时触发

    window.onscroll = function(){
        console.log("滚动条正在滚动");
    }

    function resizeHandler(){   
        console.log("窗口大小改变",window.innerWidth,window.innerHeight);

        // document.body 快捷获取body元素
        if(window.innerWidth>1200){ //PC
            document.body.style.backgroundColor = "#6ff";
        }else if(window.innerWidth>=1024){//平板
            document.body.style.backgroundColor = "orange";
        }else if(window.innerWidth>768){  // 平板
            document.body.style.backgroundColor = "pink";
        }else if(window.innerWidth>320){  // 移动端
            document.body.style.backgroundColor = "green";
        }else{
            document.body.style.backgroundColor = "#000";
        }
    }



</script>

</html>